package halberd.io;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import halberd.ImgIn;
import halberd.data.ImgData;
import halberd.data.ImgDataFactory;
import halberd.utils.BufferedImageToImgData;

public class FileIn implements ImgIn<File>{
	public ImgData convert(File file) {
		if(file==null){
			return null;
		}
        BufferedImage bi = null;  
        try {  
            bi = ImageIO.read(file);  
        } catch (Exception e) {  
            e.printStackTrace();  
            return null;
        }  
        int h=bi.getHeight();
        int w=bi.getWidth();
        ImgData imgData=ImgDataFactory.createImgData(w,h);
        BufferedImageToImgData.fillRGB(bi, imgData); 
        return imgData;
	}
	

}
